/*
 * Copyright 2016-2021 the original author.All rights reserved.
 * Kingstar(aiteasoft@163.com)
 * The license,see the LICENSE file.
 */

package com.aiteasoft.school.scores.rest;

import static com.automvc.common.service.CommService.isNullPara;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.teasoft.bee.osql.service.ObjSQLRichService;

import com.aiteasoft.school.scores.entity.Scores;
import com.aiteasoft.school.scores.service.ScoresService;
import com.automvc.common.jq.PageWarp;
import com.automvc.common.jq.Result;

/**
 * @author AiTeaSoft.com
 * @since  1.9
 * Create on 2021-01-18 18:29:19
 */
@RestController
@RequestMapping("scores")
public class ScoresRest {
	@Autowired
	ObjSQLRichService objSQLRichService;

	@Autowired
	ScoresService scoresService;

	@RequestMapping("/list")
	public Result list(Scores scores, 
			@RequestParam(value = "page", defaultValue = "1", required = false) int page,
			@RequestParam(value = "rows", defaultValue = "20", required = false) int rows) {

		Result result = new Result();
		if (isNullPara(result, scores)) return result;
		scores = scoresService.process(scores);
		
		PageWarp pageWarp = scoresService.countAndSelect(scores, (page - 1) * rows, rows);
		result.setTotal(pageWarp.getTotal());
		result.setRows(pageWarp.getList());

		return result;
	}

}